<?php
/**
 * 套餐管理
 * @author Administrator
 */

class taocan extends admin{
   public function __construct(){
      parent::__construct();
      //array_walk_recursive($_GET,'safe_filter');
      //array_walk_recursive($_POST,'safe_filter');
   }

   public function index(){
      $school_id=(int)$_SESSION['client']['jx_id'];
      $where=' where school_id='.$school_id;
      $where.=' and is_del=0';
      $taocan = db()->getAll('select * from x_taocan '.$where);
      if(!$taocan) $taocan=array();
      $this->ajaxReturn(array('status'=>1,'data'=>$taocan));
   }

   public function update(){
      $id=(int)$_POST['id'];
      $data['title']=trim($_POST['title']);
      $data['tags']=trim($_POST['tags']);
      $data['fymx']=trim($_POST['fymx']);
      $data['fwcn']=trim($_POST['fwcn']);
      $data['price']=$_POST['price'];
      $data['price']=$_POST['price'];
      $data['is_bukao']=$_POST['is_bukao'];
      $data['is_xueshi']=$_POST['is_xueshi'];
      $data['xueshi']=$_POST['xueshi']?$_POST['xueshi']:0;
      $affert_num=db()->update('x_taocan',$data,'id='.$id);

      if($affert_num!==false) {
         if($affert_num>0) insertlogs('update','修改套餐(ID:'.$id.')',$data,$id);
         $this->ajaxReturn(array('status'=>'1','info'=>'操作成功'));
      }
      else $this->ajaxReturn(array('status'=>'0','info'=>'操作失败'));
   }

   public function add(){
      if(empty($_POST['title'])) $this->ajaxReturn(array('status'=>0,'info'=>'缺少参数'));
      if(!is_numeric($_POST['price'])) $this->ajaxReturn(array('status'=>0,'info'=>'参数不正确'));
      $data['school_id'] = (int)$_SESSION['client']['jx_id'];
      $data['title']=trim($_POST['title']);
      $data['tags']=trim($_POST['tags']);
      $data['fymx']=trim($_POST['fymx']);
      $data['fwcn']=trim($_POST['fwcn']);
      $data['price']=$_POST['price'];
      $data['is_bukao']=$_POST['is_bukao'];
      $data['is_xueshi']=$_POST['is_xueshi'];
      $data['xueshi']=$_POST['xueshi']?$_POST['xueshi']:0;
      $insert_id=db()->insert('x_taocan',$data);

      if($insert_id) {
         insertlogs('create','添加套餐(ID:'.$insert_id.')',$data,$insert_id);
         $this->ajaxReturn(array('status'=>'1','info'=>'操作成功'));
      }
      else $this->ajaxReturn(array('status'=>'0','info'=>'添加失败'));
   }

   public function del(){
      $id=$_POST['id'];
      if($id<=0) $this->ajaxReturn(array('status'=>'0','info'=>'参数错误'));
      $data['is_del'] = 1;
      $affert_rows=db()->update('x_taocan',$data,'id='.$id);
      if($affert_rows) {
         insertlogs('update','删除套餐(ID:'.$id.')',$data,$id);
         $this->ajaxReturn(array('status'=>'1','info'=>'删除成功'));
      }
      else $this->ajaxReturn(array('status'=>'0','info'=>'删除失败'));
   }
}
